package com.ws.controller;

import com.ws.bean.Categories;
import com.ws.service.CategorieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/categorie")
public class CategorieController {
    @Autowired
    CategorieService categorieService;

    //查询
    @RequestMapping("list")
    public String list(Model model) {
        List<Categories> list = categorieService.list();
        model.addAttribute("list", list);
        return "categorie/list";
    }
    //去添加
    @RequestMapping("toAdd")
    public String toAdd() {
        return "categorie/add";
    }
    //添加
    @RequestMapping("add")
    public String add(Categories categories) {
        categorieService.add(categories);
        return "redirect:list";
    }
    //删除
    @RequestMapping("delete")
    public String delete(Integer id) {
        categorieService.delete(id);
        return "redirect:list";
    }

}
